<?php
/**招贤纳士
 */
namespace App\Controller\Index;

use Common\Controller\App\SignController;
use Common\Model\HrCateModel;
use Common\Model\HrListModel;
use Common\Model\HrResumeModel;

class HrController extends SignController{
    /**
     * 招贤纳士首页
     */
    public function index(){
        $model = new HrCateModel();
        $list = $model->select();
        $lmodel = new HrListModel();
        foreach($list as $k=>$v) {
            $llist = $lmodel->where("cate_id={$v['id']} and status=0")->select();
            $list[$k]['list'] = $llist;
        }
        $this->ajaxReturn(['code'=>200,'list'=>$list]);
    }

    /**
     * 获取招贤纳士详情
     */
    public function getOne(){
        $id = I('param.id'); //招聘id
        if(empty($id) || !is_numeric($id)){
            $this->ajaxReturn(['code'=>300,'msg'=>'编号错误']);
        }
        $Model = new HrListModel();
        $info = $Model->where("id=$id")->find();
        if(empty($info)){
            $this->ajaxReturn(['code'=>300,'msg'=>'此条信息不存在']);
        }
        $this->ajaxReturn(['code'=>200,'info'=>$info]);
    }

    /**
     * 申请
     */
    public function add(){
        $member_id = session('member_id');
        $id = I('param.id');
        if(empty($id) || !is_numeric($id)){
            $this->ajaxReturn(['code'=>300,'msg'=>'编号错误']);
        }
        $url = I('param.url');
        if(empty($url)){
            $this->ajaxReturn(['code'=>300,'msg'=>'请上传简历']);
        }
        $model = new HrResumeModel();
        $data['member_id'] = $member_id;
        $data['url'] = $url;
        $data['hr_id'] = $id;
        $data['create_time'] = date('Y-m-d H:i:s',time());
        $res = $model->add($data);
        if(empty($res)){
            $this->ajaxReturn(['code'=>300,'msg'=>'提交失败']);
        }else{
            $this->ajaxReturn(['code'=>200,'msg'=>'提交成功']);
        }
    }
}